home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE3 / POWERBASE / DOCS / Ch03-Print < prev    next >
Text File  |  2001-01-30  |  49KB  |  966 lines

  1. =================================
  2. Ch 3 − Printing from the Database
  3. =================================
  4.  
  5. This chapter describes how to print out selected data from a database,
  6. including the printing of individual records and of labels. Such a print-out
  7. is commonly referred to as a report.
  8.  
  9. 3.1     Output destination
  10. --------------------------
  11. Printed output may be displayed in a window, directed to a specified text
  12. file or sent straight to the printer.  Choosing Options from the Print
  13. submenu (keystroke equivalent Ctrl Print) displays the Print Options window
  14. and you will see at the top of the window three radio buttons, Window, File
  15. and Printer, which allow you to select the output destination. Each of these
  16. options will now be described.
  17.  
  18. 3.1.1   The Window destination
  19.  
  20. This is the default setting and, as its name suggests, it displays the
  21. completed report in its own window. Clicking with MENU over this window
  22. opens the Report menu which offers four choices:
  23.  
  24. Save as text leads to a Save box from which an icon may be dragged to a
  25. filer window or to any application which can accept a Text file. The
  26. supplied pathname uses an appropriate leaf-name for the file and points to a
  27. directory called PrintJobs which is inside the database directory. Each
  28. database has its own PrintJobs directory whose contents can be displayed by
  29. choosing Show jobs done (Ctrl P) from the Print submenu. To save files with
  30. the least bother simply click on Save or type Return. You can, of course,
  31. delete the pathname (Ctrl U), type in your own filename and drag the file
  32. icon to any open directory. You might also be able to produce hard copy by
  33. “saving” the text to the Printers icon on the iconbar, although some recent
  34. printers contain no fonts of their own and therefore cannot print text files
  35. in this way. Look in PrintJobs regularly and get rid of files which you no
  36. longer need.   
  37.  
  38. Sort will sort the report on whatever column the mouse pointer was over when
  39. you clicked MENU.
  40.  
  41. Shrink list will remove as much surplus “white space” as possible from
  42. between the columns of a report. This item might be shaded: white-space
  43. removal can be set to occur automatically before the report is displayed (in
  44. fact this is the default setting). If this is the case no further space can
  45. be removed and the menu choice is therefore made unavailable.
  46.  
  47. Scrap removes the report window from the screen and recovers the memory it
  48. occupied. You might find this useful if you run short of memory after
  49. creating a large report.
  50.  
  51. Calling up records from the report window
  52. -----------------------------------------
  53. The report window has one more useful feature. If you point at a particular
  54. piece of displayed data and double-click with SELECT the record window will
  55. come to the front displaying the relevant record. If the field corresponding
  56. to the item you clicked is editable the caret will be placed in that field.
  57. If you are using a report to look for errors in the data you can quickly
  58. correct them by this method but the report won’t change to reflect your
  59. corrections until you re-create it.  If you double-click with ADJUST instead
  60. of SELECT the record window opens at the pointer and its size and scrolling
  61. are adjusted to show only the required field. 
  62.  
  63. 3.1.2   The File destination    
  64.  
  65. A Save box will appear as soon as you tell Powerbase to go ahead and
  66. generate the report. The supplied pathname is the same as would be displayed
  67. when saving from the report window. Simply click Save to save it in
  68. PrintJobs under that name.  Alternatively, type a filename and drag the icon
  69. to an open directory. The report will then be created and the file closed. 
  70. Nothing else appears on the screen in this case. The File destination is of
  71. greatest use when reports are being produced from a Script file (see Ch 12).
  72.  
  73. 3.1.3   The Printer destination
  74.  
  75. When the Printer radio button is selected the More button alongside becomes
  76. available. (It is shaded when Window or File is selected.) Clicking More
  77. opens the Printer Setup window which provides a wide range of options. You
  78. may specify the number of copies to print, choose the font and point-size to
  79. be used, print with the paper upright (portrait) or sideways (landscape) and
  80. set the inter-line spacing and any or all of the four margins. All
  81. measurements other than font size may be specified in mm (default), inches
  82. or points.      
  83.  
  84. 3.2     Print formats
  85. ---------------------
  86. Powerbase is capable of producing reports in four different formats. Only
  87. two of these, Horizontal and Vertical, are available when you print to a
  88.  
  89.                                 - 16 -
  90.  
  91. window or a file and these are selected via two radio buttons on the Print
  92. Options window. When the output destination is Printer two additional
  93. formats, Table and Label, are also available and are selected from the
  94. Printer Setup window. These four formats will now be described.
  95.  
  96. 3.2.1   Horizontal
  97.  
  98. This is so-called because each record appears on a single, horizontal line
  99. with the fields aligned so that they form neat columns. Non-numeric fields
  100. are left-justified. Numeric fields, and others whose content is treated as a
  101. numeric value (see 3.5.2), are right-justified. A header line identifies the
  102. columns by means of the tags or descriptors of the fields and this header
  103. can be made to appear on every page of the report or on the first page only.
  104. An optional descriptive title may also be incorporated. The Spacer is used
  105. to separate columns (see 3.10). All these features (and others) are chosen
  106. from the Print Options window.
  107.  
  108. Besides the ability to sort a report in a window (see 3.1.1) you may force
  109. Powerbase to sort the report before displaying it. To do so, select the Sort
  110. on option button in the Print Options window and enter in the associated
  111. writable icon either the tag of the field on which you wish to sort or the
  112. column number of the report. The feature is only of use in Horizontal and
  113. Table formats, but may be used with the Printer destination as well as with
  114. Window.
  115.  
  116. 3.2.2   Vertical        
  117.  
  118. Fields are printed underneath each other with the identifier (tag or
  119. descriptor) at the left  hand side. Where the field selection includes an
  120. external text file, i.e a Text or Text block field, the Vertical format is
  121. the only one which may be used and will be selected automatically.  Although
  122. each field normally occupies a line to itself you can override this by
  123. holding down Shift as you click with ADJUST to select the field. You will
  124. then not get a new line after the field: the next field to be selected will
  125. appear (with its identifier) on the same line. We will call this function
  126. field concatenation.  It may be applied to any number of fields: keep Shift
  127. down while selecting all except the last one to appear on the line.  This
  128. feature is very useful if your report contains a mixture of long fields
  129. which need a line each and short ones which don’t and would otherwise result
  130. in wasted space and paper.  Concatenated fields are separated by the Spacer
  131. and the width of the report is governed by Text width  (see 3.10).
  132.  
  133. 3.2.3   Table
  134.  
  135. This is only available when outputting to the printer. It resembles
  136. Horizontal format but the lines and columns are separated by horizontal and
  137. vertical rules, forming a grid. When this format is selected a number of
  138. extra features are enabled allowing you to include extra (blank) columns and
  139. lines, making this format especially useful when you want a list to which
  140. information is to be added by hand (e.g. entering marks against a printed
  141. list of students). The number and width of blank columns and the number of
  142. extra lines may be specified. For a tidy result it is recommended that you
  143. increase the line-spacing from the default 120% to about 150% when using
  144. Table format.
  145.  
  146. 3.2.4   Label   
  147.  
  148. This is meant for printing on special label stationery. Since such
  149. stationery is expensive you are advised to try out your settings on plain
  150. paper first! Selecting this format enables the label setup choices which
  151. include the label size and the number of labels in a row. It also allows
  152. optional fixed starting and finishing lines to appear on each label. The
  153. number of lines on the label is not needed: Powerbase works this out from
  154. the label height and print size. 
  155.  
  156. Printing will normally begin on the first label in the first row on the
  157. sheet but, to enable you to use up a part sheet of labels, you may specify
  158. which label to begin with, e.g. for three-in-a-row labels, entering 5 would
  159. make printing start at the second label of the second row. After the first
  160. sheet the starting-point reverts to the first label in the first row.        
  161.  
  162. Each field normally appears on a separate line but fields may be
  163. concatenated in the same way as for Vertical format, with the Spacer being
  164. used to separate the fields (see 3.10).  This may be necessary if you are
  165. using separate fields for surname and initials or surname and forename.
  166.  
  167. You may specify one field to be substituted for another if the latter is
  168. blank. Both fields are specified by tag and the Substitute switch is set.
  169. This is useful in a school or college situation where labels are being
  170. addressed to parents.  Mature students, for whom the “parent” field in the
  171. record is blank, can have their own names printed instead. Another switch
  172. makes the primary key of the record appear in small print on each label as a
  173.  
  174.                                 - 17 -
  175.  
  176. means of identification. This can be useful if the data printed on the label
  177. doesn’t make it obvious which record it comes from.    
  178.  
  179. 3.3     What types of field can be printed? 
  180. -------------------------------------------
  181. Powerbase can use many different types of field.  All are described in 4.2.5
  182. in connection with setting up a new database and you should refer to that
  183. section to clarify what follows here. You can print data from the following
  184. types of field:
  185.  
  186. (1)     Any Editable field (i.e.one into which you can type directly),
  187.         including Scrollable lists.
  188.  
  189. (2)     Computed and Stamp fields.         
  190.  
  191. (3)     Text and Text block fields.         
  192.  
  193. (4)     Check Boxes. What is printed for these differs from what you see in
  194.         the check box.
  195.  
  196. Thus:   (a) Tick/Cross  boxes result in “Yes” or “No”           
  197.         (b) Tick/Blank  boxes result in “Yes” or “-”            
  198.         (c) Star/Blank  boxes result in an asterisk or “-”
  199.         (d) Null/Tick/Cross boxes result in “-”, “Yes” or “No” 
  200.         (e) ?/Tick/Cross boxes result in “?”, “Yes” or “No”
  201.  
  202. Note that (d) and (e) are three-state check-boxes; (a), (b) and (c) are
  203. two-state check-boxes. It is, of course, possible to print Draw and Sprite
  204. fields from individual records by loading the external file into Draw or
  205. Paint and printing from that application (See 2.6.2).
  206.  
  207. 3.4     Specifying which fields to print
  208. ----------------------------------------
  209. The field or fields selected for printing is called a print selection. Point
  210. at each of the required fields and click with ADJUST. The fields will be
  211. highlighted by reversing the foreground and background colours. Only those
  212. fields which are printable (see 3.3) will respond to ADJUST in this way.  A
  213. second click will de-select the field. Note that the order in which you
  214. select the fields is important since that is the order in which they will
  215. appear in the report. The menu button at the bottom-centre of the Match
  216. window (see 3.5) will list the fields in the order in which they have been
  217. selected. Ctrl F has the same effect. (If no fields are selected Ctrl F
  218. gives a listing of all the fields.)
  219.  
  220.         A contiguous range of fields may be selected by placing the caret in
  221. the first field then double-clicking with ADJUST in the last.  To select all
  222. printable fields choose Select all (Ctrl A) from the Print submenu.  There
  223. is also a Clear selection entry on this submenu (Ctrl Z).
  224.  
  225. 3.4.1   Saving print selection files
  226.  
  227. Print selections may be saved for future use. Save selection from the Print
  228. submenu leads to a Save box. Accepting the default pathname will save the
  229. file with the name Selection in a directory called PrintRes. Just as every
  230. database has its PrintJobs directory, so does it also have its own PrintRes
  231. (i.e. “Print Resources”) directory whose contents can be displayed with Show
  232. resources (Ctrl R) from the Print submenu. Selection files are of type &7f3
  233. and are distinguished by their icon which bears a large S. Because they have
  234. a specific file-type which Powerbase recognizes they can be loaded by
  235. double-clicking on them. 
  236.  
  237. 3.4.2   Default selection
  238.  
  239. You may save as many print selections as you like and use any file-names,
  240. but one name is special: a file saved as !Selection is treated as a default
  241. selection. When you instruct Powerbase to create a report without having
  242. first highlighted the fields to be included, the default selection will be
  243. searched for in PrintRes and used. If there is no such file the primary key
  244. field(s) will be printed. As soon as the report is complete the selection is
  245. cleared. You won’t see the highlighting of the fields at all when a
  246. selection is used automatically in this way.
  247.  
  248.         To save a default selection you need only select the option button
  249. Default selection in the Save box and accept the supplied pathname by
  250. clicking Save or typing Return.
  251.  
  252. 3.5     Specifying which records to print
  253. -----------------------------------------
  254. Unless we want to print all the records in the database we need some means
  255. of telling Powerbase what are the common features of the records we wish to
  256. print. There are two ways of doing this. The more versatile way (and the one
  257. which Powerbase uses by default) makes use of a search formula or query
  258.  
  259.                                 - 18 -
  260.  
  261. describing the characteristics of the required records.  The remainder of
  262. this section deals with the construction and use of search formulae.  For
  263. the alternative method, query by example see Section 3.6.  
  264.  
  265. If you choose Print from the main menu a small window with the title Find
  266. matching records appears. We will call this the Match window.  The same
  267. thing happens if you go to the Print submenu and choose Create report.
  268. Simplest of all is to just type the Print key on the keyboard. The most
  269. prominent feature of the Match window is a group of icons enclosed by a thin
  270. red border. This object is called the Query panel and you may have already
  271. seen it since it forms part of several windows. It appears when you select
  272. the Filter switch on the keypad for example (see 2.3.3) and is also used
  273. when making Global changes (2.5.5), performing a Move/delete operation on a
  274. batch of records (2.5.6), doing a Mail merge (9.2.2), exporting a CSV file
  275. (8.3) and creating a Subset (Ch 13).
  276.  
  277.         The writable icon in the Query panel, in whatever context the latter
  278. appears, is meant to take a search formula. The simplest thing you can do,
  279. of course, is to type nothing at all! If you then click on the Print  button
  280. you will create a list of all the records in the current subfile of the
  281. database. You could achieve the same result by typing ALL*, indeed if after
  282. producing the above list with a null formula you click on the Old button
  283. (Ctrl O), which retrieves the last-used search formula, you will find ALL
  284. displayed.
  285.  
  286. 3.5.1   The construction of search formulae
  287.  
  288. Most database queries will involve a selected group of records. A search
  289. formula describes the criteria which records must fulfil in order to be
  290. included in the report. Getting to grips with search formulae is, perhaps,
  291. the biggest hurdle faced by the new Powerbase user and you are referred
  292. first to the simple examples described in the Tutorial file. A search
  293. formula consists of one or more search elements. A search element specifies
  294. that a field value must fit a certain condition and takes the form:
  295.  
  296.         <TAG LIST><COMPARATOR><TARGET LIST> 
  297.  
  298. The angle brackets are there for clarity and are not used in entering the
  299. actual formula. There must be no spaces between the three parts. A tag list
  300. (if it contains more than a single tag) has the form:
  301.  
  302.         tag1,tag2,tag3,.... 
  303.  
  304. where tag1 etc. are field tags (see 4.2.1 and 4.2.4) which identify the
  305. fields to be matched. A target list (if it contains more than a single
  306. target) has the form:- 
  307.  
  308.         target1,target2,target3,.... 
  309.  
  310. If the Case switch on the Query panel is selected then all comparisons will
  311. be case-specific, e.g. “Cat” will be regarded as different from “CAT” or
  312. “cat”. If the Case switch is not selected all those three will be considered
  313. identical. Fields are normally listed in ascending alphabetical order or,
  314. for numeric fields, ascending numerical order. If the Reverse switch on the
  315. Query panel is set they will appear in reverse order. 
  316.  
  317. The heading of a report shows which fields were used in the search formula
  318. and what targets were specified. If a target was placed in quotes (which is
  319. the only way of searching for any string containing a comma, for example)
  320. then it appears in quotes in the heading also.  
  321.  
  322. It is impossible to describe the use of search formulae adequately without
  323. quoting actual examples. As in the Tutorial file we will mainly make use of
  324. the Elements sample database.  A simple example of a search formula
  325. consisting of a single search element is:
  326.  
  327.         GP=T 
  328.  
  329. where GP is the field tag, = is the comparator and T is the target. This
  330. means “The field whose tag is GP must contain the value T”, i.e. all
  331. transition elements (but no others) are to be included in the report. A
  332. slightly more complex one is: 
  333.  
  334.         GP=1,2,3 
  335.  
  336. which would be interpreted as “The GP field must match one of 1,2 or 3”.
  337. This may also be entered as:
  338.  
  339.         GP=1 OR GP=2 OR GP=3
  340.  
  341. which is possibly easier to understand but also somewhat longer.  A further
  342. example is:
  343.  
  344.         OX1,OX2,OX3=3
  345.  
  346. meaning “One of the first three oxidation state fields must have the value
  347. 3”. 
  348.                                 - 19 - 
  349.  
  350. This could also be entered as:    OX1=3 OR OX2=3 OR OX3=3
  351.  
  352. Yet another way is:               OX1-OX3=3                
  353.  
  354. i.e. you may specify a range of adjacent fields by giving the first and last
  355. separated by a hyphen.  Where you don’t know which fields to test you can
  356. replace the tag, tag list or tag range with @, which causes all the fields
  357. in the record to be examined.
  358.  
  359. Note that in these examples only one of the fields in the tag list is
  360. required to match one of the targets in the target list (although it doesn’t
  361. matter if more than one field matches more than one target). Sometimes we
  362. want an inclusive search so that all of the fields in the tag list match a
  363. given target or, less frequently, a field contains all of the values in the
  364. target list. It’s a matter of connecting the search elements with AND
  365. instead of OR. You can do exactly that:
  366.  
  367.         OX1=3 AND OX2=3 AND OX3=3
  368.  
  369. You may also save typing by using the ampersand (&) instead of the word AND,
  370. but the same result can be achieved even more briefly by simply doubling the
  371. comparator, in other words using == instead of = so that the formula
  372. becomes: 
  373.  
  374.         OX1,OX2,OX3==3
  375.  
  376. The full list of available comparators is:
  377.  
  378.  =, <>, <, >, <=, >=, { and  }{       (N.B. ~ may be used instead of <>)
  379.  
  380. { should be read as “contains” and  }{  as “does not contain”.  These are
  381. used where the target value must (or must not) be part of the field but
  382. isn’t expected to make up the whole field.  The use of { is the main source
  383. of those rare instances where we want all the items in a target list to be
  384. matched in a given field. e.g. Suppose we knew that someone’s house number
  385. was 17 and that they lived on “<something> Avenue” but the actual name
  386. couldn’t be remembered.  In a database of addresses a search formula such
  387. as:
  388.  
  389.         ADDR{{17,Avenue
  390.  
  391. (note the doubled comparator) would find it, whereas: 
  392.  
  393.         ADDR{17,Avenue
  394.  
  395. would find all those addresses where the house number was 17, regardless of
  396. street name, and all those addresses with “Avenue” in them, whatever the
  397. house number. 
  398.  
  399. You may invert the logic of a search criterion by putting  NOT in front of
  400. it. To print all non-transition elements you could use:
  401.  
  402.         NOT (GP=T) 
  403.  
  404. Note the space after NOT, the need for brackets, and that the syntax isn’t
  405. GP NOT=T. You could equally well use one of the following:
  406.  
  407.         GP<>T or GP~T
  408.  
  409. and may find either of these more understandable. To make multi-criterion
  410. searches  either place tags and targets in comma-separated lists as
  411. described above or string search elements together with the connectives AND
  412. and OR. Use AND (or the ampersand, &) when a field must meet all of a set of
  413. criteria. e.g.
  414.  
  415.         GP=T & Z>50 & NAME{IUM
  416.  
  417. for all transition metals with atomic numbers greater than 50 and names
  418. containing IUM. Use OR when a field need meet only one of a set of criteria.
  419. e.g.
  420.  
  421.         GP=L OR GP=A 
  422.  
  423. would find all lanthanide and actinide elements as the formula means “either
  424. L or A; I don’t care which”. AND and OR can produce ambiguous search
  425. formulae e.g.
  426.  
  427.         GP=1 OR GP=2 AND Z<50
  428.  
  429. could mean either “elements in group 1 or 2 (don’t care which) with atomic
  430. numbers less than 50” or  “group 1 elements (of any atomic number) or group
  431. 2 elements whose atomic numbers are less than 50”. You probably want the
  432. former, but Powerbase will give you the latter. To get what you require use
  433. brackets to make the logic clear. In other words write it as:
  434.  
  435.         (GP=1 OR GP=2) AND Z<50
  436.  
  437. You could also write this as:  GP=1,2 & Z<50  without the need for brackets
  438. at all.
  439.  
  440.                                 - 20 -
  441.  
  442. 3.5.2   Numeric and other special fields in search formulae
  443.  
  444. For most types of field the comparison with the target is made by character
  445. matching but for certain types the comparison uses the  numeric value of the
  446. field. The fields concerned are:       
  447.  
  448. Numeric, Calculated, Record number, Sequence number, Day of month, Month
  449. number, Year
  450.  
  451. Only the first of these is an editable field type but all may be included in
  452. search formulae.  Suppose we have a Numeric field whose tag is NUM.  If you
  453. entered the formula: 
  454.  
  455.         NUM=5
  456.  
  457. the record would be included in the report if NUM contained 5, 05, 5.0 etc.
  458. because all of these have the same numeric value. If you had an Alphanumeric
  459. field called NUM the same search formula would only match records where the
  460. content was literally 5, i.e. the character “5”. This can easily catch you
  461. out. Suppose, for example, you want to print records for which NUM<8. You
  462. might be surprised to find records in which NUM contains values such as 55,
  463. 20, or 13 being printed, as well as those containing 4, 6, 2 etc!  If this
  464. happens check what type of field NUM is.  Unrestricted and Alphanumeric
  465. fields will give the above result; Numeric fields (and the others listed
  466. above) will give the result you probably want.
  467.  
  468. You can force a comparison by numeric value for a field which consists of
  469. (or, at least, begins with) numerals, even though the field is not defined
  470. as of Numeric type,  by enclosing the field tag in square brackets, e.g.
  471. [NUM]<8 would produce the desired result in the above example even if the
  472. field is Alphanumeric or Unrestricted. This is useful where you want to make
  473. a comparison but still allow the field to accept non-numeric characters. The
  474. comparison-by-value can only work in such cases if the number part of the
  475. field comes first. e.g. it will deal correctly with 55A, 20B, 13X but not
  476. with A55, B20, X13. 
  477.  
  478. 3.5.3   Using “wild-cards” in search formulae
  479.  
  480. The use of characters “$” and “#” as “wild-cards” was described in 2.5.5 in
  481. connection with search-and-replace operations. They may be also be used in
  482. search formulae. “$” is used to represent a group of characters and “#” to
  483. represent single characters which do not need to be matched.  e.g. If (still
  484. using the Elements database) you type: 
  485.  
  486.         NAME=$ON
  487.  
  488. you are, in effect, saying “find all the elements whose names end in ON; I
  489. don’t care what precedes ON as long as nothing follows it”. Powerbase will
  490. duly find CARBON, BORON, NEON etc.  If you were to use:
  491.  
  492.         NAME=$ON$
  493.  
  494. You would find PLUTONIUM, POLONIUM but not CARBON, BORON, NEON; something
  495. must precede ON as well as follow it. (To print both sets of elements you
  496. would use NAME{ON.)  Note also that:
  497.  
  498.         NAME=$TIN$
  499.  
  500. finds PROTOACTINIUM,  PLATINUM etc, but not TIN itself. 
  501.  
  502.         NAME=S$IUM
  503.  
  504. finds all names which begin with S and end with IUM, e.g. SAMARIUM,
  505. SCANDIUM, and SODIUM.  The effect of:
  506.  
  507.         NAME=S####IUM
  508.  
  509. is somewhat different. You are, again, asking for names which begin with S
  510. and end with IUM but this time SAMARIUM and SCANDIUM would be found, but not
  511. SODIUM since you have specified exactly 4 wild-carded letters between the S
  512. and the I.  Finally, to find any 5-letter name, regardless of the actual
  513. letters:
  514.  
  515.         NAME=#####
  516.  
  517. 3.5.4   Comparing the contents of two fields    
  518.  
  519. A field tag (instead of a literal string) may be specified as a target, thus
  520. allowing two fields in a record to be compared to produce, for example,  a
  521. list of all records in which the relevant fields have the same content. 
  522. This might interfere with a “normal” query where the required literal target
  523. happens to be the same as the tag of another field. The problem can be
  524. overcome by enclosing the literal string in quotes.
  525.  
  526. 3.5.5   Saving search formulae for re-use
  527.  
  528. Choosing Save query from the Print submenu opens a Save box from which the
  529. search formula may be saved. By default the file is saved in PrintRes under
  530. the name Query. Selecting the Save as default switch on the Save box will
  531.  
  532.                                 - 21 -
  533.  
  534. cause the file to be saved as the default query with the name !Query. If
  535. such a file exists in PrintRes it will be automatically entered in the Query
  536. panel whenever the Match window is opened. A default query file, in other
  537. words, behaves in a similar way to a default selection file as described in
  538. 3.4.2. Query files are of type &7f4 and are recognizable by the large Q in
  539. their icon. You may save as many Query files as you like and load them into
  540. the query panel by double-clicking on them.
  541.  
  542. 3.6     Query by example
  543. ------------------------
  544. After that lengthy description of the search formula method of querying the
  545. database we turn to the alternative: query by example.  For brevity when
  546. comparing the two we will refer to them as SF and QBE respectively.  Select
  547. the option switch at the top left of the Match window in order to use QBE. 
  548.  
  549. 3.6.1   What is QBE?
  550.  
  551. The user is presented with a blank record and invited to type into the
  552. relevant fields the data which must be matched in order for the record to be
  553. included in the report. What you are saying in effect is: “I want a list of
  554. all records which look like this. I don’t care what’s in any of the fields I
  555. haven’t filled in, but the ones I have filled in must correspond to what I
  556. have typed.”  e.g. in the Elements database if you wanted to print a list of
  557. all transition metals you would simply enter T in the Group field and then
  558. proceed with the report.  The tag of the field isn't needed at all, whereas
  559. using a search formula requires you to type GP=T. Enter the data to be
  560. matched then  either click with SELECT on the Print button of the Match
  561. window or else press the Print key.
  562.  
  563. If you simply enter the required target strings Powerbase assumes that you
  564. want the relevant fields to match exactly, i.e the effect is the same as
  565. using “=” in a search formula. There are, however, other  comparators
  566. besides “=” which may be used in search formulae. (see 3.5.1 for explanation
  567. and complete list). You may use any of these in a QBE query by placing them
  568. at the start of the string, e.g. {Avenue in an Address field would match all
  569. records where the field contained the word “Avenue”.  An address such as “15
  570. Acacia Avenue” could be found by this method whereas just entering the word
  571. “Avenue” wouldn’t work because it would require the field to read “Avenue”
  572. and nothing more. 
  573.  
  574. Wildcards may be used; e.g. you could print from the Elements database all
  575. elements ending in IUM by entering $IUM in the NAME field or all those whose
  576. symbol began with H by entering H# in the SYM field.    
  577.  
  578. You may specify a target list (see 3.5.1) to make the search include all
  579. records matching any item in the list. e.g. Leeds,Liverpool,Manchester in a
  580. Town field (if it will fit) would cause records with any of these places to
  581. be included. You can also specify a field list (equivalent to a tag list;
  582. see 3.5.1) provided that the fields form a contiguous group. The target
  583. string (which may be a target list, be wild-carded or be preceded by a
  584. comparator) is entered in the first field of the group. Press Return and
  585. enter " (double quote or “ditto” mark) in the next field and for the
  586. remaining fields of the group. (Pressing Return rather than moving the caret
  587. by means of the mouse ensures that you really are dealing with a contiguous
  588. group of fields.)
  589.  
  590. 3.6.2   QBE vs SF
  591.  
  592. So what are the advantages and disadvantages?  QBE is very intuitive and
  593. avoids the need to bother with field tags or the minutiae of search formula
  594. syntax. On the other hand SF is more comprehensive and flexible: there are
  595. some things you simply cannot do with QBE.  Some of the limitations have
  596. already been mentioned but here is a complete list.
  597.  
  598. •       Except where exact matches (“field=target string”) are required it
  599.         might not be possible to fit the target string or list into the
  600.         relevant field.  One consequence is that you can't target a Date
  601.         field for all dates prior to, say, 01-06-90 since dates fit their
  602.         fields exactly leaving no room for the necessary < comparator.  Such
  603.         a search is perfectly possible with SF.
  604.  
  605. •       Searches involving multiple fields and the same target, i.e. those
  606.         where FieldX or FieldY or FieldZ must match are only possible where
  607.         the fields form a contiguous sequence. With SF it is possible to
  608.         perform such searches on fields dotted about the record.
  609.  
  610. •       There is no equivalent in QBE to the @= (any field in the record
  611.         matches) or @{ (any field contains) searches which are possible with
  612.         SF.
  613.  
  614. •       You can't search for text in an external Text or Text Block field.
  615.         You can with SF.
  616.  
  617.                                 - 22 -
  618.  
  619. •       You can't include Check-box fields in QBE searches.
  620.  
  621. •       Since QBE doesn't use tags you can’t force a
  622.         comparison-by-numeric-value on a non-numeric field (See 3.5.2).
  623.  
  624. •       Calculated fields and those belonging to the Stamp class cannot be
  625.         used by QBE because you cannot type into them!
  626.  
  627. If your requirements involve only fairly simple searches then QBE might be
  628. just what you’ve been looking for, but if complex multiple searches are
  629. often needed then SF is the one to go for. It is, of course, a simple matter
  630. to switch between the two.
  631.  
  632. As supplied Powerbase uses SF as the default query method and the Query by
  633. example switch will be deselected when the Match window is displayed. If you
  634. want to make QBE the default you can edit the relevant line of the Config
  635. file in !Powerbase.Resources to read Query QBE instead of Query SF. Don’t
  636. forget the space. Selecting the Print function will then produce the blank
  637. record without displaying the Match window at all.  There is, of course, no
  638. Print button to click with the mouse after you have entered the target
  639. strings so you tell Powerbase proceed by typing the Print key after entering
  640. the data to be matched.
  641.  
  642. 3.7     Other features of the Query panel and Match window
  643. ----------------------------------------------------------
  644. At the far left of the Match window is a group of four radio buttons
  645. labelled Print, Count, Mark and Clear. Only one of these may be selected at
  646. a time and the default action button at the bottom right of the window
  647. reflects whichever one you select. When the Match window is opened it is
  648. always Print which is selected, this being the most often used feature. If
  649. you merely want to know how many records match a specified set of criteria,
  650. without printing them, select Count. The number of matching records appears
  651. to the left of the Cancel button (which merely closes the window).  Mark and
  652. Clear are explained in section 3.8.2 below.
  653.  
  654. The icon to the left of Cancel indicates the selected output destination
  655. (see 3.1) by displaying a representation of a window, a text-file icon, or a
  656. printer. In the latter case the icon will be shaded if no printer driver is
  657. loaded. Clicking with SELECT on the icon opens the Print Options window.
  658.  
  659. Old, as stated earlier, retrieves the last search formula used. The action
  660. of the Case and Reverse switches has also been described (see 3.5.1).       
  661.  
  662. Help opens the Help window which offers another way of building search
  663. formulae which might appeal to beginners. Select the target field by cycling
  664. through the tags with the bump icons or by choosing from the pop-up menu. 
  665. Choose the comparator by selecting a radio button. Type the target value
  666. into the writable icon. Place the caret in the Query panel writable icon and
  667. click Add to formula.  The search element will appear at the caret.  You may
  668. click on AND or OR and enter other search elements in the same way. If you
  669. wish to use the NOT button you must do so before clicking Add to formula. 
  670. Powerbase inserts the brackets round the search element for you.       
  671.  
  672. Holding down Ctrl and clicking on a field with SELECT while the caret is in
  673. the Query panel causes the tag of the field to be entered in the search
  674. formula at the caret. This, together with the above method of constructing
  675. search formulae, largely overcomes the problem (especially when using
  676. someone else’s database) of not remembering what the field tags are.      
  677.  
  678. 3.7.1   Printing records from more than one subfile
  679.  
  680. Reports are usually created from records in the currently-selected subfile
  681. which is displayed in the title bar of the record window. Just under the
  682. Query panel is the legend Incl.subfiles: and a row of numerals, 0-5. When a
  683. database is opened 0 will be highlighted, indicating that reports will only
  684. include records from subfile 0. If you change subfile by clicking on the
  685. appropriate keypad buttons you will see this highlighting move from one
  686. number to another, showing the selected subfile. You can, however, click on
  687. these numbers so that any or all of them are selected. Subfiles are
  688. deselected with a second click. 
  689.  
  690. When you create a report from more than one subfile the records are not
  691. merged into one alphabetically (or numerically) ordered list; the ordering
  692. starts afresh for each selected subfile. This isn’t really a problem because
  693. you can always sort the completed report  on any field to produce a single,
  694. ordered list (see 3.1.1).
  695.  
  696. 3.7.2   Including record number, key and subfile number
  697.  
  698. A group of three option switches in a frame to the left of the query panel
  699. allow you to include record numbers, the current key, and the subfile number
  700. in a report. The latter is especially useful if you have created a report
  701. from several subfiles and then sorted it as described above. If you need to
  702.  
  703.                                 - 23 -
  704.  
  705. keep track of which subfile a record comes create the report with File
  706. selected. These three special items are not saved with a print selection
  707. file and always appear on a report before any of the selected fields.     
  708.  
  709. 3.8     Marking records for inclusion or exclusion
  710. --------------------------------------------------
  711. There are times when you want to print a number of records which have no
  712. obvious connection with one another: they may have a common feature which is
  713. obvious to you but none within the records themselves.  Such a situation
  714. commonly occurs when you want to print a few mailing labels.  No common
  715. feature means no basis for constructing a search formula. So how do you tell
  716. Powerbase which records you want to print? 
  717.  
  718. 3.8.1   Single records  
  719.  
  720. A small panel attached to the bottom of the record window* contains a
  721. check-box, Mark for printing etc., which you can tick to indicate that the
  722. displayed record is to be printed.  Using the Search button or the browse
  723. controls you can call up each record you want and tick the box. You then
  724. simply select the required fields and print in the usual way. If no search
  725. formula has been entered then only the marked records will be printed.
  726. (Printing without a search formula when no records are marked gives the
  727. whole subfile as described in 3.5)  If you do enter a search formula you
  728. will get the records which match the formula plus the marked records,
  729. whether the latter match the formula or not.
  730.  
  731. A pop-up menu allows you to invert the effect of this feature so that
  732. printing without a search formula gives all records in the subfile except
  733. the marked ones and printing with a search formula gives all the matching
  734. records except for those marked. When the menu option is set like this (to
  735. exclude rather than include) the check box shows a red cross instead of a
  736. green tick. 
  737.  
  738. Next to the check-box is the Clear marks button which does exactly what it
  739. says. It is shaded when no record is marked. A further indication of whether
  740. records are marked is provided by the small rectangle at the far right of
  741. the Query panel which is coloured green or red, as appropriate, when any
  742. record is marked. This applies to the whole database, by the way, not just
  743. to the current subfile.
  744.  
  745. Powerbase takes heed of marked records in any operation which involves the
  746. query panel, i.e. batch move/delete, global change, filter, export subset,
  747. export CSV file, as well as print. 
  748.  
  749. 3.8.2   Groups of records
  750.  
  751. It is sometimes useful to be able to mark (or clear marks from) a group of
  752. records which fit a search formula. This is made possible by the Mark and
  753. Clear radio buttons on the Match window.  By repeatedly selecting Mark and
  754. executing different query operations you can build up a set of marked
  755. records by stages then, if desired, selectively clear the marks from certain
  756. ones. Finally, you can print your carefully-tailored selection of marked
  757. records without entering a search formula at all.
  758.  
  759. 3.9     Printing single records
  760. -------------------------------
  761. There are two methods of printing the displayed record only:
  762.  
  763. (a) Hold down Shift whilst clicking with SELECT on the Print button of the
  764. Match window or type Shift Print on the keyboard. The highlighted fields of
  765. the displayed record are printed using the currently-selected print format
  766. as determined by the setting in the Print options window.  If no fields are
  767. selected the action is as described in 3.4.2; Powerbase will use the default
  768. selection if it exists or, failing that, print the primary key fields only. 
  769.  
  770. (b) Follow Export selected from the main menu to a Save box from which may
  771. be saved (or dragged to the printer or into a wordprocessor document) a text
  772. file containing the highlighted fields of the displayed record. If there are
  773. no fields selected the menu entry is shaded.
  774.  
  775. 3.10    The Print options window 
  776. --------------------------------
  777. To display this window you can choose Options from the Print submenu, type
  778. Ctrl Print, or click SELECT on the icon to the left of Cancel on the Match
  779. window. Features such as Destination (see 3.1), Format (see 3.2)  and the
  780. Sort on facility (see 3.2.1) have already been dealt with extensively. The
  781. rest are covered here. Default settings appear in brackets after the name of
  782. the feature.
  783.  
  784. Scrollable lists (as single row) These may be printed in two different ways.
  785.  
  786.                                 - 24 -
  787.  
  788. The default is for all the cells in the list to be made into a single row
  789. with semicolons separating the data from individual rows of the scroller.
  790. This can result in very long lines indeed. An option switch (Shrink row - ON
  791. by default) causes as much white space as possible to be removed, but lines
  792. could still be too long for the printer. The alternative format puts the
  793. data from each row of the scroller on a separate line so that the data
  794. aligns in columns. This occupies less room horizontally but much more
  795. vertically.  Experiment!
  796.  
  797. Headings (tags) appear at the head of reports in all formats except Label
  798. unless None is selected.
  799.  
  800. Expand codes (OFF) causes extra data from a validation table to be
  801. substituted for (or added to) the coded data in fields linked to such tables
  802. (see 5.2).
  803.  
  804. Expand headers (ON) will show the expanded versions (see 5.2) of the target
  805. values for fields linked to validation tables in the list header.  Turning
  806. the option OFF causes the target values to be shown exactly as typed in the
  807. search formula.
  808.  
  809. Upper case (OFF) causes all textual output to appear in capital letters.
  810.  
  811. Print header (ON) causes the printing of header lines at the beginning of
  812. each page.  The header includes the following information:
  813.  
  814. •       The name of the database plus a title, derived from the search
  815.         formula, making it clear on what basis the records have been chosen.
  816.  
  817. •       The index used for the ordering, plus the date stamp (if appropriate
  818.         switch selected).
  819.  
  820. •       An optional description entered in the Title writable icon.    
  821.  
  822. •       The column headings as described above.
  823.  
  824. The following switch (on p. 1 only: default OFF) limits the header to the
  825. first page of a report.
  826.  
  827. Print footer (ON). Reports in Horizontal and Table format normally end with
  828. a footer which specifies the number of records printed.  If the output
  829. includes Numeric fields and column calculations have been selected (see 6.4)
  830. then the results of these too will be part of the footer. 
  831.  
  832. Date stamp (ON) makes the date and time when the report was created appear
  833. as part of the header.                                       
  834.  
  835. Shrink list (ON). In Horizontal and Table format the width of columns is
  836. determined by the maximum defined length of the fields included in the print
  837. selection. These lengths are often greater than the length of data actually
  838. present in the fields, resulting in a lot of “white space” between columns.
  839. With this option ON the surplus space will be automatically removed. Even if
  840. it is OFF you can still remove white space via the Report menu (see 3.1.1).
  841. Output to Printer always removes white space whether this switch is ON or
  842. OFF
  843.  
  844. Page numbers (OFF) allows page numbers  to appear at the bottom of each page
  845. of a report. This feature works quite independently of the Print footer
  846. switch.
  847.  
  848. Page length (0) determines the total length of page, including header,
  849. footer and top margin, for destinations other than Printer (for which the
  850. page length is determined by the printer driver).  The default value of 0
  851. means no division into pages at all, but you might want to alter this if you
  852. drag text-files to the printer. An A4 page is 70 lines long, but you won’t
  853. be able to print on them all and page-feeds might occur in the wrong place.
  854. Look at Edit paper sizes on the iconbar menu of Printers. Subtract the
  855. displayed top and bottom text margins from 70 and enter the value in place
  856. of 64, if necessary. In Vertical format Powerbase will try to avoid
  857. splitting a record between pages, but this can happen if the report includes
  858. Text or Text Block fields of greatly varying length. (It will also happen if
  859. the number of fields to be printed exceeds the length of the page!)
  860.  
  861. Text width (A) specifies the line length used when printing in Vertical
  862. format. A means “Auto” and lets the program calculate the value. You may
  863. enter a value of your own (e.g. 70) to override this.
  864.  
  865. Spacer (1) specifies how fields printed on the same line will be separated.
  866. Fields are first padded with spaces to the maximum width of the relevant
  867. data field (but see Shrink list above) and the spacer string is then printed
  868. before starting the next field. Three interpretations of the contents of
  869. this setting are possible:
  870.  
  871. •       A number by itself means use the specified number of spaces.
  872.  
  873. •       A number followed by a non-numeric character means use a string of
  874.         the specified number of that character, e.g. “3-” means 3 hyphens. 
  875.  
  876. •       A non-numeric string is used “as is”, e.g.“|” or “ | ”. If the
  877.         former is used when outputting to Printer continuous vertical rules
  878.         will be placed between columns in Horizontal format.
  879.  
  880.                                 -  25 -
  881.  
  882. 3.10.1 Saving print options files
  883.  
  884. All the settings in the Print Options and Printer Setup windows may be saved
  885. as a Print Options file. Clicking Save choices with the in database radio
  886. button selected brings up the familiar Save box. By default the file is
  887. saved in PrintRes under the name PrintOpts. As with Selection (see 3.4.1)
  888. and Query files (see 3.5.5) you can save a default options file called
  889. !PrintOpts by selecting the Default options button on the Save box and
  890. Powerbase will load this whenever the database is opened. Options files have
  891. a large P on their icon and a filetype of &7f5. You may save as many as you
  892. wish and load them with a double-click. If the in Powerbase radio button is
  893. selected the options are saved as the Powerbase default and no Save box is
  894. displayed. Load default reloads this file, overwriting any changed settings.
  895.  
  896. 3.11    Field analysis reports
  897. ------------------------------
  898. The Field submenu has an Analyse option which allows you to print a
  899. breakdown of the field contents under certain special circumstances:
  900.  
  901. (a)  If the field is indexed the menu entry will read Analyse index. When
  902. chosen it will produce a list of all the values in the index with the number
  903. of times each one occurs. e.g. A database of college students might have a
  904. field for the school of origin. If there are 20 different schools and if the
  905. field is indexed then a list of those schools will be generated showing how
  906. many students came from each school. 
  907.  
  908. (b) If the field contains an 8 or 10 character date (e.g. 19-10-42 or
  909. 19-10-1942) the menu entry reads Analyse months and a breakdown by month
  910. will be printed. There will be a line for each month showing the number of
  911. records for that month. For example, this could be used in an orders
  912. database to find out quickly how many orders were received or dispatched
  913. each month. This feature works on editable Date fields and also on Date
  914. stamp8 and Date stamp10 fields in the Stamp class.
  915.  
  916. It is, of course, possible for a field containing a date to be indexed.
  917. Action (a), above, takes precedence in such a case. You can, however, force
  918. action (b) instead by first selecting the field with ADJUST, then choosing
  919. from the menu. For cases not described above the menu entry simply says
  920. Analyse and is shaded. Printing is always to a window (from which the report
  921. may, of course, be saved); the Destination buttons in the Print options
  922. window have no effect.
  923.  
  924. 3.12    Subsidiary indices and printing speed
  925. ---------------------------------------------
  926. Try the following experiment using the sample database Elements :
  927.  
  928. (1)     Create a subsidiary index, if one doesn’t already exist, on the
  929.         Group field (see 7.1 for the way to do this). Don’t make the index
  930.         case-specific
  931.  
  932. (2)     Enter the formula GP=T and click Print with ADJUST so that the Match
  933.         window remains open. Note the time taken for creating the report. 
  934.  
  935. (3)     Deselect the Case button and repeat the process.  The time will be
  936.         shorter.  You might also notice the brief appearance of a numeral
  937.         (probably 1) in the small rectangle to the right of the search
  938.         formula in the Query panel.
  939.  
  940. The speed increase is most noticeable with a slow machine such as an A3000. 
  941. On a StrongArm RiscPC and with such a small database both times will be so
  942. short that the user’s reaction might be “So what?” but when dealing with
  943. databases of thousands of records the improvement can be quite dramatic.
  944.  
  945. What happens is that Powerbase detects the fact that there is an index based
  946. on the Group (GP) field, goes straight to the first occurrence of “T” in
  947. that index then prints records for as long as the key remains “T”.  The
  948. number briefly displayed in the Query panel is the number of the index being
  949. used and its appearance shows the user that a subsidiary index is being
  950. used.  If you look at the header of the report you will see that it says
  951. “Ordered by GP index” whereas the first time it said “Ordered by
  952. PrimaryKey”.  The speed-up only works when the all following conditions are
  953. met:
  954.  
  955. •       The search formula must include a simple comparison for equality,
  956.         i.e. of the type TAG=target, without alternatives: no OR, no tag
  957.         list,  no target list.
  958.  
  959. •       The whole of the field represented by TAG must be indexed.
  960.  
  961. •       The Case switch on the Query panel must be set to agree with the
  962.         index, i.e. it must be selected if the index is case-specific and
  963.         deselected if not.
  964.  
  965.                                 - 26 -
  966.